<? include 'server_config.php';

if($_SESSION['user_idx'] == "")
{
	?>
	<script>
		location.href='login.php';
	</script>
	<?
	return;
}
$key = $_GET['key'];
?>
<list><?
	if(preg_match("/^(ㄱ)$/",$key)) {
		$pattern = "ProductNameKr REGEXP '^(ㄱ)' OR ( ProductNameKr >= '가' AND ProductNameKr < '까' )";
	} elseif(preg_match("/^(ㄲ)$/",$key)) {
		$pattern = "ProductNameKr REGEXP '^(ㄲ)' OR ( ProductNameKr >= '까' AND ProductNameKr < '나' )";
	} elseif(preg_match("/^(ㄴ)$/",$key)) {
		$pattern = "ProductNameKr REGEXP '^(ㄴ)' OR ( ProductNameKr >= '나' AND ProductNameKr < '다' )";
	} elseif(preg_match("/^(ㄷ)$/",$key)) {
		$pattern = "ProductNameKr REGEXP '^(ㄷ)' OR ( ProductNameKr >= '다' AND ProductNameKr < '따' )";
	} elseif(preg_match("/^(ㄸ)$/",$key)) {
		$pattern = "ProductNameKr REGEXP '^(ㄸ)' OR ( ProductNameKr >= '따' AND ProductNameKr < '라' )";
	} elseif(preg_match("/^(ㄹ)$/",$key)) {
		$pattern = "ProductNameKr REGEXP '^(ㄹ)' OR ( ProductNameKr >= '라' AND ProductNameKr < '마' )";
	} elseif(preg_match("/^(ㅁ)$/",$key)) {
		$pattern = "ProductNameKr REGEXP '^(ㅁ)' OR ( ProductNameKr >= '마' AND ProductNameKr < '바' )";
	} elseif(preg_match("/^(ㅂ)$/",$key)) {
		$pattern = "ProductNameKr REGEXP '^(ㅂ)' OR ( ProductNameKr >= '바' AND ProductNameKr < '빠' )";
	} elseif(preg_match("/^(ㅃ)$/",$key)) {
		$pattern = "ProductNameKr REGEXP '^(ㅃ)' OR ( ProductNameKr >= '빠' AND ProductNameKr < '사' )";
	} elseif(preg_match("/^(ㅅ)$/",$key)) {
		$pattern = "ProductNameKr REGEXP '^(ㅅ)' OR ( ProductNameKr >= '사' AND ProductNameKr < '싸' )";
	} elseif(preg_match("/^(ㅆ)$/",$key)) {
		$pattern = "ProductNameKr REGEXP '^(ㅆ)' OR ( ProductNameKr >= '싸' AND ProductNameKr < '아' )";
	} elseif(preg_match("/^(ㅇ)$/",$key)) {
		$pattern = "ProductNameKr REGEXP '^(ㅇ)' OR ( ProductNameKr >= '아' AND ProductNameKr < '자' )";
	} elseif(preg_match("/^(ㅈ)$/",$key)) {
		$pattern = "ProductNameKr REGEXP '^(ㅈ)' OR ( ProductNameKr >= '자' AND ProductNameKr < '짜' )";
	} elseif(preg_match("/^(ㅉ)$/",$key)) {
		$pattern = "ProductNameKr REGEXP '^(ㅉ)' OR ( ProductNameKr >= '짜' AND ProductNameKr < '차' )";
	} elseif(preg_match("/^(ㅊ)$/",$key)) {
		$pattern = "ProductNameKr REGEXP '^(ㅊ)' OR ( ProductNameKr >= '차' AND ProductNameKr < '카' )";
	} elseif(preg_match("/^(ㅋ)$/",$key)) {
		$pattern = "ProductNameKr REGEXP '^(ㅋ)' OR ( ProductNameKr >= '카' AND ProductNameKr < '파' )";
	} elseif(preg_match("/^(ㅍ)$/",$key)) {
		$pattern = "ProductNameKr REGEXP '^(ㅍ)' OR ( ProductNameKr >= '파' AND ProductNameKr < '타' )";
	} elseif(preg_match("/^(ㅌ)$/",$key)) {
		$pattern = "ProductNameKr REGEXP '^(ㅌ)' OR ( ProductNameKr >= '타' AND ProductNameKr < '하' )";
	} elseif(preg_match("/^(ㅎ)$/",$key)) {
		$pattern = "ProductNameKr REGEXP '^(ㅎ)' OR ( ProductNameKr >= '하' AND ProductNameKr <= '힣' )";
	} else{
		$pattern = "ProductNameKr REGEXP '.*(".$key.").*'";
	}
	$sql = "
		SELECT ProductNameKr FROM ndd_list_drug WHERE $pattern ORDER BY ProductNameKr ASC LIMIT 0,20
	";

	$result = mysql_query($sql,$connect);

	while($row = mysql_fetch_row($result))
	{
		$ProductNameKr = $row[0];
		echo "<drug>" . $ProductNameKr . "</drug>" ;
	}

?>
</list>
